package com.wenx.v3system.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityScheme;
import io.swagger.v3.oas.models.servers.Server;

import java.util.List;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wenx
 * @description openapi config
 */
@Configuration
public class OpenApiConfig {

    @Bean
    public OpenAPI springOpenAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("V3 系统管理服务 API")
                        .description("V3微服务架构")
                        .version("1.0.0")
                        .contact(new Contact()
                                .name("wenx")
                                .email("wenxpro@outlook.com")
                                .url("https://gitee.com/wenxpro"))
                        .license(new License()
                                .name("MIT License")
                                .url("https://opensource.org/licenses/MIT")))
                // 配置OAuth2认证
                .components(new Components().addSecuritySchemes("bearer-key",
                        new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("bearer")));
    }

    /**
     * sys 分组
     *
     * @return sys分组接口
     */
    @Bean
    public GroupedOpenApi adminApi() {
        return GroupedOpenApi.builder()
                .group("sys接口")
                .packagesToScan("com.wenx.v3system.modular.rbac.controller")
                .pathsToMatch("/api/v3/sys/**")
                .build();
    }

    /**
     * tenant 分组
     * @return tenant分组接口
     */
    @Bean
    public GroupedOpenApi tenantApi() {
        return GroupedOpenApi.builder()
                .group("tenant接口")
                .packagesToScan("com.wenx.v3system.modular.tenant.controller")
                .pathsToMatch("/api/v3/t/**")
                .build();
    }

}